package com.xgq.drink.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xgq.drink.entity.FavoriteBrand;
import com.xgq.drink.entity.FavoriteProduct;
import com.xgq.drink.mapper.FavoriteBrandMapper;
import com.xgq.drink.service.IFavoriteBrandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class FavoriteBrandServiceImpl extends ServiceImpl<FavoriteBrandMapper, FavoriteBrand> implements IFavoriteBrandService {

    /**
     * 检查是否已收藏该品牌
     */
    @Override
    public boolean isFavoriteBrand(Long userId, Long brandId) {
        return baseMapper.selectCountByUserIdAndBrandId(userId, brandId) > 0;
    }
    @Override
    public int logicDeleteByUserIdAndFavoriteBrandId(Long userId, Long favoriteBrandId) {
        QueryWrapper<FavoriteBrand> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        queryWrapper.eq("brand_id", favoriteBrandId);
        // 获取收藏商品列表
        FavoriteBrand favoriteProductPage = baseMapper.selectOne(queryWrapper);
        favoriteProductPage.setIsDel(1);
        System.out.println(favoriteProductPage.getFavoriteBrandId());
        System.out.println(favoriteProductPage.toString());
        return baseMapper.logicDeleteByUserIdAndFavoriteBrandId(userId,favoriteProductPage.getFavoriteBrandId());
    }
}